package edu.gatech.stolen.tea;

import java.io.Serializable;
import java.util.Collection;
import java.util.HashMap;
import java.util.Map;

/**
 * This class will hold the user accounts
 * @author Leshi
 *
 */
public class Accounts implements Serializable {
	/**
	 * 
	 */

	private static Map<String, String> accounts = new HashMap<String, String>();
	private static Map<String, User> users= new HashMap<String, User>();
	private static final long serialVersionUID = 1L;

	/**
	 * the account holder that holds all user login information
	 */


	/**
	 * Creates a new user
	 * if the username already exist, the user will not be created
	 * @param username
	 * @param password
	 * @return
	 */
	static public boolean createUser(String username, String password){
		if (checkExistingUser(username)){
			//notify the user here
			return false;
		}else{
			accounts.put(username, password);
			users.put(username, new User(username));
			return true;
		}
	}
	/**
	 * check whether username already exist
	 * @param newUser
	 * @return true if already exist, false otherwise
	 */
	static  private boolean checkExistingUser(String newUser) {
		if(accounts.containsKey(newUser)){
			return true;
		}else{
			return false;
		}
		
	}
	/**
	 * log in the user
	 * @param username
	 * @param password
	 * @return true if successful, false otherwise
	 */
	static public boolean login(String username, String password){
		if (checkExistingUser(username)){
			if(accounts.get(username).equals(password)){
				return true;
			}
		}
		//notify the user of wrong login info
		return false;
	}
	/**
	 * 
	 * @param the current user name
	 * @return a corrisponding user object
	 */
	static public User getCurrentUser(String user){
		return users.get(user);
	}
}
